package com.rpj.stauy.config;

import com.rpj.stauy.service.MyAiService;
import dev.langchain4j.model.chat.ChatModel;
import dev.langchain4j.model.openai.OpenAiChatModel;
import dev.langchain4j.service.AiServices;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.time.Duration;
import java.util.List;

@Configuration
public class AiConfig {

    @Bean("qwen")
    public ChatModel chatModelQwen(){
        return OpenAiChatModel.builder()
                .modelName("qwen-plus")
                .baseUrl("https://dashscope.aliyuncs.com/compatible-mode/v1")
                .apiKey(System.getenv("aliQwen_api"))
                .logRequests(true)//请求日志
                .logResponses(true)//响应日志
                .listeners(List.of(new MyChatModelistener())) // 监听器
                .maxRetries(3) //重试
//                .timeout(Duration.ofSeconds(1)) //超时
                .build();
    }

    @Bean("aiservice")
    public MyAiService myAiService(){
        return AiServices.create(MyAiService.class,chatModelQwen());
    }

}
